/*
 *
 *    Copyright (c) 2022 Project CHIP Authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

// THIS FILE IS GENERATED BY ZAP
// This file is generated from clusters-Structs.ipp.zapt

#include <clusters/Thermostat/Structs.h>

#include <app/data-model/StructDecodeIterator.h>
#include <app/data-model/WrappedStructEncoder.h>

namespace chip
{
namespace app
{
	namespace Clusters
	{
		namespace Thermostat
		{
			namespace Structs
			{

				namespace ScheduleTransitionStruct
				{
					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kDayOfWeek), dayOfWeek);
						encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime);
						encoder.Encode(to_underlying(Fields::kPresetHandle), presetHandle);
						encoder.Encode(to_underlying(Fields::kSystemMode), systemMode);
						encoder.Encode(to_underlying(Fields::kCoolingSetpoint),
							       coolingSetpoint);
						encoder.Encode(to_underlying(Fields::kHeatingSetpoint),
							       heatingSetpoint);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kDayOfWeek)) {
								err = DataModel::Decode(reader, dayOfWeek);
							} else if (__context_tag ==
								   to_underlying(Fields::kTransitionTime)) {
								err = DataModel::Decode(reader, transitionTime);
							} else if (__context_tag ==
								   to_underlying(Fields::kPresetHandle)) {
								err = DataModel::Decode(reader, presetHandle);
							} else if (__context_tag ==
								   to_underlying(Fields::kSystemMode)) {
								err = DataModel::Decode(reader, systemMode);
							} else if (__context_tag ==
								   to_underlying(Fields::kCoolingSetpoint)) {
								err = DataModel::Decode(reader, coolingSetpoint);
							} else if (__context_tag ==
								   to_underlying(Fields::kHeatingSetpoint)) {
								err = DataModel::Decode(reader, heatingSetpoint);
							}

							ReturnErrorOnFailure(err);
						}
					}

				} // namespace ScheduleTransitionStruct

				namespace ScheduleStruct
				{
					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kScheduleHandle), scheduleHandle);
						encoder.Encode(to_underlying(Fields::kSystemMode), systemMode);
						encoder.Encode(to_underlying(Fields::kName), name);
						encoder.Encode(to_underlying(Fields::kPresetHandle), presetHandle);
						encoder.Encode(to_underlying(Fields::kTransitions), transitions);
						encoder.Encode(to_underlying(Fields::kBuiltIn), builtIn);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kScheduleHandle)) {
								err = DataModel::Decode(reader, scheduleHandle);
							} else if (__context_tag ==
								   to_underlying(Fields::kSystemMode)) {
								err = DataModel::Decode(reader, systemMode);
							} else if (__context_tag == to_underlying(Fields::kName)) {
								err = DataModel::Decode(reader, name);
							} else if (__context_tag ==
								   to_underlying(Fields::kPresetHandle)) {
								err = DataModel::Decode(reader, presetHandle);
							} else if (__context_tag ==
								   to_underlying(Fields::kTransitions)) {
								err = DataModel::Decode(reader, transitions);
							} else if (__context_tag == to_underlying(Fields::kBuiltIn)) {
								err = DataModel::Decode(reader, builtIn);
							}

							ReturnErrorOnFailure(err);
						}
					}

				} // namespace ScheduleStruct

				namespace PresetStruct
				{
					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kPresetHandle), presetHandle);
						encoder.Encode(to_underlying(Fields::kPresetScenario), presetScenario);
						encoder.Encode(to_underlying(Fields::kName), name);
						encoder.Encode(to_underlying(Fields::kCoolingSetpoint),
							       coolingSetpoint);
						encoder.Encode(to_underlying(Fields::kHeatingSetpoint),
							       heatingSetpoint);
						encoder.Encode(to_underlying(Fields::kBuiltIn), builtIn);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kPresetHandle)) {
								err = DataModel::Decode(reader, presetHandle);
							} else if (__context_tag ==
								   to_underlying(Fields::kPresetScenario)) {
								err = DataModel::Decode(reader, presetScenario);
							} else if (__context_tag == to_underlying(Fields::kName)) {
								err = DataModel::Decode(reader, name);
							} else if (__context_tag ==
								   to_underlying(Fields::kCoolingSetpoint)) {
								err = DataModel::Decode(reader, coolingSetpoint);
							} else if (__context_tag ==
								   to_underlying(Fields::kHeatingSetpoint)) {
								err = DataModel::Decode(reader, heatingSetpoint);
							} else if (__context_tag == to_underlying(Fields::kBuiltIn)) {
								err = DataModel::Decode(reader, builtIn);
							}

							ReturnErrorOnFailure(err);
						}
					}

				} // namespace PresetStruct

				namespace PresetTypeStruct
				{
					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kPresetScenario), presetScenario);
						encoder.Encode(to_underlying(Fields::kNumberOfPresets),
							       numberOfPresets);
						encoder.Encode(to_underlying(Fields::kPresetTypeFeatures),
							       presetTypeFeatures);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kPresetScenario)) {
								err = DataModel::Decode(reader, presetScenario);
							} else if (__context_tag ==
								   to_underlying(Fields::kNumberOfPresets)) {
								err = DataModel::Decode(reader, numberOfPresets);
							} else if (__context_tag ==
								   to_underlying(Fields::kPresetTypeFeatures)) {
								err = DataModel::Decode(reader, presetTypeFeatures);
							}

							ReturnErrorOnFailure(err);
						}
					}

				} // namespace PresetTypeStruct

				namespace ScheduleTypeStruct
				{
					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kSystemMode), systemMode);
						encoder.Encode(to_underlying(Fields::kNumberOfSchedules),
							       numberOfSchedules);
						encoder.Encode(to_underlying(Fields::kScheduleTypeFeatures),
							       scheduleTypeFeatures);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kSystemMode)) {
								err = DataModel::Decode(reader, systemMode);
							} else if (__context_tag ==
								   to_underlying(Fields::kNumberOfSchedules)) {
								err = DataModel::Decode(reader, numberOfSchedules);
							} else if (__context_tag ==
								   to_underlying(Fields::kScheduleTypeFeatures)) {
								err = DataModel::Decode(reader, scheduleTypeFeatures);
							}

							ReturnErrorOnFailure(err);
						}
					}

				} // namespace ScheduleTypeStruct

				namespace WeeklyScheduleTransitionStruct
				{
					CHIP_ERROR Type::Encode(TLV::TLVWriter &aWriter, TLV::Tag aTag) const
					{
						DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
						encoder.Encode(to_underlying(Fields::kTransitionTime), transitionTime);
						encoder.Encode(to_underlying(Fields::kHeatSetpoint), heatSetpoint);
						encoder.Encode(to_underlying(Fields::kCoolSetpoint), coolSetpoint);
						return encoder.Finalize();
					}

					CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader)
					{
						detail::StructDecodeIterator __iterator(reader);
						while (true) {
							uint8_t __context_tag = 0;
							CHIP_ERROR err = __iterator.Next(__context_tag);
							VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV,
									    CHIP_NO_ERROR);
							ReturnErrorOnFailure(err);

							if (__context_tag == to_underlying(Fields::kTransitionTime)) {
								err = DataModel::Decode(reader, transitionTime);
							} else if (__context_tag ==
								   to_underlying(Fields::kHeatSetpoint)) {
								err = DataModel::Decode(reader, heatSetpoint);
							} else if (__context_tag ==
								   to_underlying(Fields::kCoolSetpoint)) {
								err = DataModel::Decode(reader, coolSetpoint);
							}

							ReturnErrorOnFailure(err);
						}
					}

				} // namespace WeeklyScheduleTransitionStruct
			} // namespace Structs
		} // namespace Thermostat
	} // namespace Clusters
} // namespace app
} // namespace chip
